package com.mxf.code.enums;

import java.util.concurrent.TimeUnit;

/**
 * Author: panweijian
 * since: 2022/11/23
 * FileName: RedisEnum
 * Description: redis-key常量
 */
public enum RedisEnum {
    /**
     * 位置树
     */
    SPS_SPACE_TREE("space:tree", 24 * 60 * 60L, TimeUnit.SECONDS),
    SPS_SPACE_MAP("space:map", 24 * 60 * 60L, TimeUnit.SECONDS)
    ;

    //key
    private String key;
    //过期时间
    private long expire;
    //时间单位
    private TimeUnit timeUnit;

    //拼接key
    public static String join(String key, Long id) {
        return key + ":" + id;
    }

    //拼接key
    public String join(String id) {
        return this.key + ":" + id;
    }

    //获取随机过期时间(1~1000s)
    public static Long randomTime1000(Long expire) {
        return expire + (long) (Math.random() * 1000) + 1;
    }

    RedisEnum() {
    }

    RedisEnum(String key, long expire, TimeUnit timeUnit) {
        this.key = key;
        this.expire = expire;
        this.timeUnit = timeUnit;
    }

    public String getKey() {
        return key;
    }

    public long getExpire() {
        return expire;
    }

    public TimeUnit getTimeUnit() {
        return timeUnit;
    }
}
